package com.alibaba.aliper.agent;

import java.io.OutputStream;
import java.net.Socket;

import com.alibaba.aliper.agent.sys.CpuMonitor;
import com.alibaba.aliper.agent.sys.CpuPercentage;

/**
 * Hello world!
 *
 */
public class SocketClient 
{
	public static byte[] getReportBytes(String agent,String chart,String line,long time,double value){
		String message = "agent:\""+agent+"\" chart:\""+chart+"\" line:\""+line+"\" point.x:\""+time+"\" point.y:\""+(int)value+"\"\n";
		System.out.println(message);
		return message.getBytes();
	}
    public static void main( String[] args ) throws Exception
    {
     Socket socket = new Socket("localhost",8456);
    CpuMonitor monitor = new CpuMonitor();
    while(true){
    	CpuPercentage per = monitor.getCpuPercentage();
    	OutputStream out = socket.getOutputStream();
    	out.write(getReportBytes("testServer", "cpu", "user", monitor.getEndState().getTime(), (int)(per.getUser(0)*100)));
    	out.flush();
    	//remote.report("arandaServer", "linux Server2", "cpu/sys", monitor.getEndState().getTime(), per.getSystem(0));
    	Thread.sleep(100);
    }
  //  System.out.println("heart beat: " + remote.heartBeat("arandaServer"));

    }
}
